package cn.tedu.tedutest02202.web;

import cn.tedu.tedutest02202.pojo.vo.EmailVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class JsonResult<T> {
    @ApiModelProperty("提示文本")
    private String message;
    @ApiModelProperty("业务状态码")
    private Integer state;
    @ApiModelProperty("数据")
    private T data;

    public static  JsonResult<Void> ok(){
//        JsonResult<Void> jsonResult = new JsonResult<>();
//        jsonResult.setState(ServiceCode.OK.getValue());
//        jsonResult.setMessage("操作成功！");
        return JsonResult.ok(null);
    }

    public static <T> JsonResult<T> ok(T data){
        JsonResult<T> jsonResult = new JsonResult<>();
        jsonResult.state =ServiceCode.OK.getValue();
        jsonResult.data = data;//把传递进来的参数放进上面的泛型中
        return jsonResult;
    }

    public static JsonResult<Void> fail(ServiceCode code,String message){
        JsonResult<Void> jsonResult = new JsonResult<>();
        jsonResult.setState(code.getValue());
        jsonResult.setMessage(message);
        return jsonResult;
    }
}
